package com.minelx.datamicroscope.core.index;

import com.minelx.datamicroscope.ChaSessionFactory;
import com.minelx.datamicroscope.core.condition.RawCondition;
import com.minelx.datamicroscope.core.query.AliasedKey;
import com.minelx.datamicroscope.core.query.CollectingResource;
import com.minelx.datamicroscope.core.query.Query;
import com.minelx.hellopandas.core.PandasMethodProvider;
import io.gitee.minelx.filesystem.Directory;
import io.gitee.minelx.filesystem.File;
import io.gitee.minelx.filesystem.TempPath;
import io.gitee.minelx.filesystem.provider.FS;
import com.minelx.statementsplus.cha.base.ChaSession;

import java.util.Arrays;
import java.util.List;

import static io.gitee.minelx.filesystem.init.OpenPolicy.EXISTS;

public interface IndexFactory {

	Index createIndex(List<AliasedKey> remainingKeys,
					  List<RawCondition> conditions,
					  CollectingResource collectingResource,
					  File destination);

	static IndexFactory onlineIndexAndLocalStoredPandasFile() {
		return list(Arrays.asList(
				storedAt(Query.localPandas(), FS.local().dir("C:/data_microscope_stored_frames", EXISTS)),
				online(Query.localPandas(), TempPath.tempFileDirectoryAtWorkingDir(), ChaSessionFactory.configured())));
	}

	static IndexFactory list(List<ConditionalIndexFactory> conditionalIndexFactories) {
		return new AutoDeterminingIndexFactory(conditionalIndexFactories);
	}

	static ConditionalIndexFactory online(PandasMethodProvider pandasMethodProvider,
	                                      Directory cacheFilesDirectory,
	                                      ChaSession chaSession) {
		return new OnlineConditionalIndexFactory(pandasMethodProvider, cacheFilesDirectory, chaSession);
	}

	static ConditionalIndexFactory storedAt(PandasMethodProvider pandasMethodProvider, Directory storedDirectory) {
		return new StoredDataFrameDirectoryConditionalIndexFactory(pandasMethodProvider, storedDirectory);
	}
}
